package com.example.zp.adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.jbmsuppliers.R;

/**
 * Created by JBMhaier on 2017/4/25.
 */

public class MainGridAdapter extends BaseAdapter{
    private String [] title={"图片","开门授权","支付","商品列表"};
    private int[] photoArr={R.mipmap.picture,R.mipmap.open_licersing,R.mipmap.payment,R.mipmap.commodity_list};
   private Context context;
    public MainGridAdapter(Context context){
        this.context=context;

    }

    @Override
    public int getCount() {
        return title.length;
    }

    @Override
    public Object getItem(int position) {
        return title[position];
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
       if(convertView==null) {
           convertView = View.inflate(context, R.layout.item_gv, null);
           holder=new ViewHolder(convertView);
           convertView.setTag(holder);
       }else{
           holder=(ViewHolder)convertView.getTag();
       }
        holder.tv.setText(title[position]);
        Drawable res = context.getResources().getDrawable(photoArr[position]);

        res.setBounds(0, 0, res.getMinimumWidth(), res.getMinimumHeight());
        holder.tv.setCompoundDrawables(null,res,null,null);
        return convertView;
    }
    private static class ViewHolder{
        TextView tv;

        public ViewHolder(View convertView){
            tv=(TextView)convertView.findViewById(R.id.item_gv_tv);


        }

    }

}
